//
//  WBPresentationController.swift
//  WeiBo
//
//  Created by LTX on 2016/11/4.
//  Copyright © 2016年 LTX. All rights reserved.
//

import UIKit

class WBPresentationController: UIPresentationController {

    var Frame = CGRect.zero
    
    // MARK:- 懒加载属性
   fileprivate lazy var coverView : UIView = UIView()
    
    
    // MARK:- 系统回调函数
    override func containerViewWillLayoutSubviews() {
    
        super.containerViewWillLayoutSubviews()
        // 设置视图尺寸
        presentedView?.frame = Frame
        
        // 添加蒙版
        setCoverView()
        
    }
    
}

// MARK:- 设置UI界面
extension WBPresentationController{
    
    func setCoverView() {
        
        //添加蒙版
        containerView?.insertSubview(coverView, at: 0)
        
        // 设置蒙版属性
        coverView.backgroundColor = UIColor(white: 0.8, alpha: 0.2)
        coverView.frame = containerView!.bounds
        
        //添加事件监听
        let tapGes = UITapGestureRecognizer(target: self, action: #selector(coverViewTouch))
        coverView.addGestureRecognizer(tapGes)
        
    }

}


// MARK:- 事件监听
extension WBPresentationController{

  @objc fileprivate  func coverViewTouch() {
        print("点击了蒙版")
    
        presentedViewController.dismiss(animated: true, completion: nil)
    }


}





